//-----------------------------------------------------------------------
// <copyright file="TextMessageFormat.cs" company="Microsoft">
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace Microsoft.Live.Messenger
{
    using System;
    using Microsoft.Live.Core;

    /// <summary>
    /// Represents formatting for a <see cref="TextMessage"/>.
    /// </summary>
    public sealed class TextMessageFormat
    {
        private static TextMessageFormat defaultFormat;

        private readonly MessengerEntity entity;

        private readonly TextMessageColor fontColor;

        /// <summary>
        /// Initializes a new instance of the <see cref="TextMessageFormat"/> class.
        /// </summary>
        /// <param name="fontColor">The font color.</param>
        /// <param name="fontFamily">The font family.</param>
        /// <param name="fontStyle">The font style.</param>
        /// <param name="flowDirection">The flow direction of text.</param>
        public TextMessageFormat(
            TextMessageColor fontColor,
            string fontFamily,
            TextMessageStyle fontStyle,
            TextMessageDirection flowDirection)
        {
            if (fontColor == null)
            {
                throw ExceptionHelper.CreateArgumentNullException("fontColor");
            }

            if (String.IsNullOrEmpty(fontFamily))
            {
                throw ExceptionHelper.CreateArgumentNullException("fontFamily");
            }

            this.entity = MessengerEntity.CreateInstance(typeof(TextMessageFormat), fontColor.Entity, fontFamily, fontStyle, flowDirection);
            this.fontColor = fontColor;
        }

        internal TextMessageFormat(object obj) {
            this.entity = new MessengerEntity(obj);
            this.fontColor = new TextMessageColor(this.entity.GetProperty("FontColor"));
        }

        internal MessengerEntity Entity {
            get { return this.entity; }
        }

        /// <summary>
        /// Gets the default text message format.
        /// </summary>
        public static TextMessageFormat DefaultFormat
        {
            get
            {
                if (defaultFormat == null)
                {
                    defaultFormat = new TextMessageFormat(
                        MessengerEntity.GetProperty(typeof(TextMessageFormat), "DefaultFormat"));
                }
                return defaultFormat;
            }
        }

        /// <summary>
        /// Gets the font color.
        /// </summary>
        public TextMessageColor FontColor
        {
            get { return this.fontColor; }
        }

        /// <summary>
        /// Gets the font family.
        /// </summary>
        public string FontFamily
        {
            get { return this.entity.GetProperty<string>("FontFamily"); }
        }

        /// <summary>
        /// Gets the font style.
        /// </summary>
        public TextMessageStyle FontStyle
        {
            get { return this.entity.GetEnumProperty<TextMessageStyle>("FontStyle"); }
        }

        /// <summary>
        /// Gets the content flow direction for text and User interface (UI) elements.
        /// </summary>
        public TextMessageDirection FlowDirection
        {
            get { return this.entity.GetEnumProperty<TextMessageDirection>("FlowDirection"); }
        }
    }
}